﻿<div id="tree-list-demo">
    @(Html.DevExtreme().TreeList<DevExtreme.NETCore.Demos.Models.TreeList.EmployeeTask>()
        .ID("tasks")
        .DataSource(ds => ds.Mvc()
            .Controller("TreeListTasks")
            .LoadAction("Tasks")
            .UpdateAction("UpdateTask")
            .InsertAction("InsertTask")
            .DeleteAction("DeleteTask")
            .Key("Task_ID")
        )
        .KeyExpr("Task_ID")
        .ParentIdExpr("Task_Parent_ID")
        .ColumnAutoWidth(true)
        .WordWrapEnabled(true)
        .ShowBorders(true)
        .Editing(editing => editing
            .Mode(GridEditMode.Cell)
            .AllowAdding(true)
            .AllowUpdating(true)
            .AllowDeleting(true)
        )
        .Columns(columns => {
            columns.AddFor(m => m.Task_Subject)
                .MinWidth(250);

            columns.AddFor(m => m.Task_Assigned_Employee_ID)
                .MinWidth(120)
                .Lookup(lookup => lookup
                    .DataSource(ds => ds.Mvc()
                        .Controller("TreeListTasks")
                        .LoadAction("TaskEmployees")
                        .Key("ID")
                    )
                    .ValueExpr("ID")
                    .DisplayExpr("Name")
                );

            columns.AddFor(m => m.Task_Status)
                .MinWidth(120)
                .Lookup(lookup => lookup
                    .DataSource(new[] {
                        "Not Started",
                        "Need Assistance",
                        "In Progress",
                        "Deferred",
                        "Completed"
                    })
                );

            columns.AddFor(m => m.Task_Start_Date);

            columns.AddFor(m => m.Task_Due_Date);
        })
        .ColumnAutoWidth(true)
        .OnInitNewRow("treeList_onInitNewRow")
    )
</div>

<script>
    function treeList_onInitNewRow(e) {
        e.data.Task_Status = "Not Started";
        e.data.Task_Start_Date = new Date();
        e.data.Task_Due_Date = new Date();
    }
</script>
